package cn.feiding;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;



public class MyCalculatorActivity extends Activity {
	
	Button btOne;
	Button btTwo;
	Button btThree;
	Button btFour;
	Button btFive;
	
	Button btPlus;
	Button btClear;
	
	TextView tvStatus;
	TextView tvValue;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        getContext();
        
        btClear.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				setContentView(R.layout.main);
				clearAll();
			}
		});
        
        
        btOne.setOnClickListener(new OnClickListener() {
    		
    		public void onClick(View v) {
    			// TODO Auto-generated method stub
    			setContentView(R.layout.main);
    			setValue(getResources().getString(R.string.one));
    			
    			getContext();
    			//
    			setOnButtonClick();
    		}
    	}
        );
        
        
    }
    
    private void getContext(){

        btOne = (Button)findViewById(R.id.btOne);
        btTwo = (Button)findViewById(R.id.btTwo);
        btThree = (Button)findViewById(R.id.btThree);
        
        btPlus = (Button)findViewById(R.id.btPlus);
        btClear = (Button)findViewById(R.id.btClear);
        
    }
    
    /*
     * 
     * 
     * */
    private void setOnButtonClick(){
    	//
    	btOne.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				setValue(getResources().getString(R.string.one));
			}
			
		});
    	
    }
    
    private void setValue(String strValue){
    	
    	tvValue = (TextView)findViewById(R.id.txValue);
        
    	CharSequence valuePrevious = tvValue.getText();
    	tvValue.setText(valuePrevious + strValue);
    	
    }
    
    private void clearAll(){
        
        tvStatus = (TextView)findViewById(R.id.txStatus);
        tvValue = (TextView)findViewById(R.id.txValue);
        tvStatus.setText("");
        tvValue.setText("");
    }
    
    
    
}